function MainPracticeAssistant(args) {
	/*
	 * this is the creator function for your scene assistant object. It will be
	 * passed all the additional parameters (after the scene name) that were
	 * passed to pushScene. The reference to the scene controller
	 * (this.controller) has not be established yet, so any initialization that
	 * needs the scene controller should be done in the setup function below.
	 */
	this.quizStats = args;
}

MainPracticeAssistant.prototype.setup = function() {
	/*
	 * this function is for setup tasks that have to happen when the scene is
	 * first created
	 */

	/*
	 * use Mojo.View.render to render view templates and add them to the scene,
	 * if needed
	 */

	/* setup widgets here */

	/* add event handlers to listen to events from widgets */
	Mojo.Log.info('In Setup');
	this.choiceNotes = [];
	this.radioAttribs = {};
	this.sharpAttribs = {};
	this.sharpModel = {
		value : false,
		disabled : false
	};
	
	
	this.qCount = 0;
	this.selNote = "zz";
	this.selClef = 1;
	this.selSharp;

	//Disable KeyBoard for now
	$('keybd').style.display="none";
	
	
	// new 1.4.x HTML5 audio implementation setup
	this.libs = MojoLoader.require( {
		name : "mediaextension",
		version : "1.0"
	});
	this.myAudioObj = this.controller.get('noteSound');
	// this.myAudioObj = new Audio();

	// Make full screen
	this.controller.enableFullScreenMode(true);

	// Setup Choice Widget..
	this.controller.setupWidget("choiceButtons", this.radioAttribs,
			this.radioModel = {
				value : "",
				disabled : false
			});
	
	
	//Back Widget
	if(myApp.isTouchPad()){

		 var menuModel = {

		             visible: true,
		             items: [ 
		                    { icon: "back", command: "goBack"}
		             ]
		         }; 

		     this.controller.setupWidget(Mojo.Menu.commandMenu,
		         this.attributes = {
		             spacerHeight: 0,
		             menuClass: 'no-fade'
		         },
		         menuModel
		     );   

		}
	
	
	//ShowStaff is false so this is sound only
	if (!this.quizStats.showStaff) {
		$('StaffContainer').style.display = "none";
		$('AudioContainer').style.display = "block";
		// Setup Play Widget
		this.controller.setupWidget("AudioControl", this.buttonAttribs = {},
				this.buttonModel = {
					label : "Play Again",
					disabled : false
				});
		Mojo.Event.listen($('AudioControl'), Mojo.Event.tap, this
				.handlePlayAgain.bind(this));

	}

	// Create the Sharp Key.
	if (this.quizStats.qSharp) {
		Mojo.Log.info("Sharps On");
		this.controller.setupWidget("choiceSharp", this.sharpAttribs,
				this.sharpModel);
		this.selSharp = arrSharp[Math.floor(Math.random() * arrSharp.length)];
		Mojo.Log.info("Selected Sharp:" + this.selSharp.key);
	} else {
		$('sharpRow').style.display = "none";
	}
	
	
	//set Listening Events
	//
	Mojo.Event.listen(this.controller.get("choiceButtons"),
			Mojo.Event.propertyChange, this.checkChoice.bind(this));
	
	Mojo.Event.listen(this.controller.get("keybd"), 
			Mojo.Event.tap, this.pianoTap.bind(this));
	
	Mojo.Event.listen(this.controller.get("keybd"), 
			Mojo.Event.hold, this.pianoHold.bind(this));
	
	

	var canvas2 = $("music");
	var ctx2 = canvas2.getContext("2d");
	this.ctx2 = ctx2;
	this.nextQuestion();
};

MainPracticeAssistant.prototype.nextQuestion = function() {
	this.qCount++;

	if (this.qCount > this.quizStats.qSize) {
		this.endQuiz();
	} else {
		// Get the Clef && Note
		this.getClef();
		selNote = this.getNote();
		this.selNote = selNote;
		
		// Set the Question Number for User
		$("qNumber").innerHTML = this.qCount;

		//Check to see if its sound only
		//
		if (this.quizStats.showStaff) {
			// Draw Staff and Notes
			drawStaff(this.ctx2, this.selClef);

			// Set Sharp
			if (this.quizStats.qSharp) {
				sharp(this.ctx2,
						(this.selClef == 1) ? this.selSharp.trbLocation
								: this.selSharp.bssLocation);
			}

			// Draw Note
			if (selNote.Location > 170)
				upQuarter(this.ctx2, selNote.Location);
			else
				downQuarter(this.ctx2, selNote.Location);
		}
		
		
		
		this.createChoices();
	
		// Load Sound File
		Mojo.Log.info("Sound File: " + Mojo.appPath + "sounds/" + selNote.key
				+ selNote.notation + ".mp3");
		if (this.quizStats.qSound) {
			this.myAudioObj.src = Mojo.appPath + "sounds/" + selNote.key
					+ selNote.notation + ".mp3";
			this.myAudioObj.load();
			Mojo.Log.info("Audio Object Play");
			this.myAudioObj.play();
		}
		
	}
};


// Select Random Note
MainPracticeAssistant.prototype.getNote = function() {
	Mojo.Log.info("Entering GetNote::");
	selNote = "";
	// Check to see if the note is the same as the last
	// if so then get again.
	Mojo.Log.info("sel vs this.sel " + selNote + " " + this.selNote);
	while (this.selNote == selNote || selNote == "") {
		Mojo.Log.info("sel vs this.sel " + selNote + " " + this.selNote);
		if (this.selClef == 1) {
			selNote = trbNotes[Math.floor(Math.random() * trbNotes.length)];
		} else {
			selNote = bssNotes[Math.floor(Math.random() * bssNotes.length)];
		}
	}
	Mojo.Log.info("selNote Location " + selNote.Location);
	Mojo.Log.info("Exiting GetNote::");
	return selNote;

};

// Select Cleff for Quiz
// 1=Trebel
// 2=Bass
// 3=Random
MainPracticeAssistant.prototype.getClef = function() {
	cleff = this.quizStats.qClef;
	Mojo.Log.info("Selected Cleff:" + cleff);

	if (cleff == 3) {
		Mojo.Log.info("in Random Clef");
		this.selClef = Math.floor(Math.random() * 2);
	} else {
		this.selClef = cleff;
	}

};
MainPracticeAssistant.prototype.handlePlayAgain = function(event) {
	this.myAudioObj.load();
	this.myAudioObj.play();
};
MainPracticeAssistant.prototype.checkChoice = function(event) {
	Mojo.Log.info("In Check Choice: " + event.model.value);
	var selection = event.model.value;
	var isSharp = this.sharpModel.value;
	var noteKey = "";

	if (this.quizStats.nType == 1) {
		noteKey = this.selNote.key + this.selNote.notation;
	} else if (this.quizStats.nType == 2) {
		noteKey = this.selNote.key;
	} else {
		noteKey = this.selNote.sol;
	}

	Mojo.Log.info("CheckChoice::Sharp CheckBox: " + isSharp);
	if (this.quizStats.qSharp) {
		var sharpKey = this.selSharp.key;

		if (sharpKey == this.selNote.key) {
			noteKey = noteKey + "#";
		}

		if (isSharp) {
			selection = selection + "#";
		}
	}

	Mojo.Log.info("CheckChoice::Selection: " + selection + " key: " + noteKey);
	if (selection == noteKey) {
		this.controller.showAlertDialog( {
			onChoose : function(value) {
				this.correctChoice();
			},
			title : $L("You are correct!!"),
			choices : [ {
				label : $L('Continue'),
				value : "ok"
			} ]
		});
	} else {
		this.controller.showAlertDialog( {
			onChoose : function(value) {
				this.incorrectChoice();
			},
			title : $L("Wrong!"),
			message : $L("Correct Value: " + noteKey.toUpperCase()),
			choices : [ {
				label : $L('Continue'),
				value : "ok"
			} ]
		});
	}
	Mojo.Log.info("Exiting CheckChoice::");
}

MainPracticeAssistant.prototype.endQuiz = function() {
	Mojo.Controller.stageController.swapScene("QuizEnd", this.quizStats);

}

MainPracticeAssistant.prototype.correctChoice = function() {
	// Set Array for Correct Choice
	this.quizStats.qAnswers[this.qCount] = "1";
	this.nextQuestion();
}
MainPracticeAssistant.prototype.incorrectChoice = function() {
	// Set Array for Incorrect Choice
	this.quizStats.qAnswers[this.qCount] = "0";
	this.nextQuestion();
}


MainPracticeAssistant.prototype.createChoices = function() {
	selectedNote = this.selNote.key;
	Mojo.Log.info("In Create Choices:: Selected Note: " + this.selNote.key);
	this.radioAttribs.choices = [];
	// Copy the Array According to Clef
	//
	if (this.quizStats.nType == 1) {
		Mojo.Log.info("In nType 1");
		if (this.selClef == 1)
			tmpArray = trbNotes;
		else
			tmpArray = bssNotes;

		tmpArray.sort(randOrd);
		cnc = 0;
		this.choiceNotes.clear();

		for (i = 0; i < tmpArray.length; i++) {
			if (this.choiceNotes.length > 3)
				break;
			note = tmpArray[i].key;
			notation = tmpArray[i].notation;
			if (note != this.selNote.key) {
				Mojo.Log.info("Adding Note to Choices:" + note + notation);
				this.choiceNotes[cnc] = note + notation;
				cnc++;
			}
		}
		this.choiceNotes[4] = this.selNote.key + this.selNote.notation;
		this.choiceNotes.sort(randOrd);

		for (z = 0; z < this.choiceNotes.length; z++) {
			this.radioAttribs.choices[z] = {};
			this.radioAttribs.choices[z].label = this.choiceNotes[z];
			this.radioAttribs.choices[z].value = this.choiceNotes[z];

		}
	} else if (this.quizStats.nType == 2) {
		Mojo.Log.info("createChoices::nType 2");
		for (z = 0; z < keyMap.length; z++) {
			this.radioAttribs.choices[z] = {};
			this.radioAttribs.choices[z].label = keyMap[z].key;
			this.radioAttribs.choices[z].value = keyMap[z].key;
		}
		// $('choiceButtons').style.width="100%";
		$('choiceButtons').style.cssFloat = "none";
	} else {
		Mojo.Log.info("createChoices::nType 3");
		for (z = 0; z < keyMap.length; z++) {
			this.radioAttribs.choices[z] = {};
			this.radioAttribs.choices[z].label = keyMap[z].sol;
			this.radioAttribs.choices[z].value = keyMap[z].sol;
		}
		$('choiceButtons').style.cssFloat = "none";
	}

//	this.radioAttribs.value = "";
	this.radioModel.value="";
	this.controller.modelChanged(this.radioModel);
	//this.controller.setWidgetModel("choiceButtons", this.radioAttribs);
	if (this.quizStats.qSharp) {
		this.sharpModel.value = false;
		this.controller.modelChanged(this.sharpModel);
	}
	Mojo.Log.info("Exit CreateChoices::");
}

function randOrd() {
	return (Math.round(Math.random()) - 0.5);
}

MainPracticeAssistant.prototype.pianoTap = function(event){
	Mojo.Log.info("Enter PianoTap::");
	$('tappedKey').innerHTML = event.srcElement.id;
	
}

MainPracticeAssistant.prototype.pianoHold = function(event){
	Mojo.Log.info("Enter PianoHold::" + event.srcElement.id);
	$('tappedKey').innerHTML = event.srcElement.id;
	
}

MainPracticeAssistant.prototype.activate = function(event) {
	/*
	 * put in event handlers here that should only be in effect when this scene
	 * is active. For example, key handlers that are observing the document
	 */
};

MainPracticeAssistant.prototype.deactivate = function(event) {
	/*
	 * remove any event handlers you added in activate and do any other cleanup
	 * that should happen before this scene is popped or another scene is pushed
	 * on top
	 */
};

MainPracticeAssistant.prototype.cleanup = function(event) {
	/*
	 * this function should do any cleanup needed before the scene is destroyed
	 * as a result of being popped off the scene stack
	 */

};
